<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
		var arr = [30,9,5,7,20,100,8];
		//快速排序
		// 找到中间位，比中间位小的放左边，比中间位大的放右边
		function quickSort(arr){
			if(arr.length<1){return arr}; //如果长度小于1 直接返回
			var index = Math.floor(arr.length/2); //获取中间index
			var center = arr.splice(index,1)[0]; //返回中间的数据
			var left = [];
			var right = [];
			for(var i=0;i<arr.length;i++){
				if(arr[i]<center){left.push(arr[i])} //比中间位小的放左边
				else{right.push(arr[i])} //比中间位大的放右边
			}
			console.log(left,center,right);
			return quickSort(left).concat(center,quickSort(right));  //递归排序
			
		}
		var re = quickSort(arr);
		console.log("结果：",re)
		</script>
	</body>
</html>
